# service variables
SET(STREAMER_SERVICE_PORT 6317)
SET(STREAMER_SERVICE_HOST "127.0.0.1:${STREAMER_SERVICE_PORT}") # service endpoint
SET(STREAMER_SERVICE_HTTP_PORT 8000)
SET(STREAMER_SERVICE_HTTP_HOST "0.0.0.0:${STREAMER_SERVICE_HTTP_PORT}") # hls endpoint
SET(STREAMER_SERVICE_VODS_PORT 7000)
SET(STREAMER_SERVICE_VODS_HOST "0.0.0.0:${STREAMER_SERVICE_VODS_PORT}") # vods endpoint
SET(STREAMER_SERVICE_CODS_PORT 6001)
SET(STREAMER_SERVICE_CODS_HOST "0.0.0.0:${STREAMER_SERVICE_CODS_PORT}") # cods endpoint
SET(STREAMER_SERVICE_CODS_TTL 600)
SET(STREAMER_SERVICE_FILES_TTL 604800) #7 days (7 * 24 * 3600)
SET(STREAMER_SERVICE_STREAMLINK_PATH "/usr/local/bin/streamlink")
SET(STREAMER_SERVICE_NAME_EXE ${STREAMER_SERVICE_NAME}_s)
SET(STREAMER_EXE_NAME stream)

FIND_PACKAGE(Common REQUIRED)
FIND_PACKAGE(FastoTvCPP REQUIRED)
FIND_PACKAGE(JSON-C REQUIRED)
FIND_PACKAGE(OpenSSL REQUIRED)

# platform specific
IF(OS_WINDOWS)
  SET(PLATFORM_HEADER)
  SET(PLATFORM_SOURCES)
  SET(PLATFORM_LIBRARIES ws2_32 psapi)
  SET(RELATIVE_SOURCE_DIR .)
ELSEIF(OS_LINUX)
  SET(PLATFORM_HEADER)
  SET(PLATFORM_SOURCES)
  SET(PLATFORM_LIBRARIES dl)
  SET(RELATIVE_SOURCE_DIR ..)

  FIND_LIBRARY(UDEV_LIBRARY udev)
  FIND_PATH(UDEV_INCLUDE_DIR NAMES libudev.h)
  IF(UDEV_LIBRARY AND UDEV_INCLUDE_DIR)
    SET(PLATFORM_LIBRARIES ${PLATFORM_LIBRARIES} ${UDEV_LIBRARY})
  ENDIF(UDEV_LIBRARY AND UDEV_INCLUDE_DIR)
  IF (PLATFORM_ARM)
    FIND_LIBRARY(ATOMIC_LIBRARY NAMES atomic atomic.so.1 libatomic.so.1)
    IF(ATOMIC_LIBRARY)
      SET(PLATFORM_LIBRARIES ${PLATFORM_LIBRARIES} ${ATOMIC_LIBRARY})
    ENDIF(ATOMIC_LIBRARY)
  ENDIF(PLATFORM_ARM)
ELSEIF(OS_MACOSX)
  FIND_LIBRARY(FOUNDATION_LIBRARY Foundation)
  FIND_LIBRARY(IOKIT_LIBRARY IOKit)
  SET(PLATFORM_HEADER)
  SET(PLATFORM_SOURCES)
  SET(PLATFORM_LIBRARIES dl ${FOUNDATION_LIBRARY} ${IOKIT_LIBRARY})
  SET(RELATIVE_SOURCE_DIR ..)
ELSEIF(OS_FREEBSD)
  SET(PLATFORM_HEADER)
  SET(PLATFORM_SOURCES)
  SET(PLATFORM_LIBRARIES dl)
  SET(RELATIVE_SOURCE_DIR ..)

  FIND_LIBRARY(UDEV_LIBRARY udev)
  FIND_PATH(UDEV_INCLUDE_DIR NAMES libudev.h)
  IF(UDEV_LIBRARY AND UDEV_INCLUDE_DIR)
    SET(PLATFORM_LIBRARIES ${PLATFORM_LIBRARIES} ${UDEV_LIBRARY})
  ENDIF(UDEV_LIBRARY AND UDEV_INCLUDE_DIR)
ELSEIF(OS_POSIX)
  SET(PLATFORM_HEADER)
  SET(PLATFORM_SOURCES)
  SET(PLATFORM_LIBRARIES udev dl)
  SET(RELATIVE_SOURCE_DIR ..)
ENDIF(OS_WINDOWS)

IF(USE_PTHREAD)
  IF(NOT OS_ANDROID)
   SET(PLATFORM_LIBRARIES ${PLATFORM_LIBRARIES} pthread)
  ENDIF(NOT OS_ANDROID)
ENDIF(USE_PTHREAD)

SET(PIPE_HEADERS ${CMAKE_SOURCE_DIR}/src/server/pipe/client.h)
SET(PIPE_SOURCES ${CMAKE_SOURCE_DIR}/src/server/pipe/client.cpp)

SET(TCP_HEADERS ${CMAKE_SOURCE_DIR}/src/server/tcp/client.h)
SET(TCP_SOURCES ${CMAKE_SOURCE_DIR}/src/server/tcp/client.cpp)

SET(UTILS_HEADERS ${CMAKE_SOURCE_DIR}/src/server/utils/utils.h)
SET(UTILS_SOURCES ${CMAKE_SOURCE_DIR}/src/server/utils/utils.cpp)

SET(OPTIONS_HEADERS ${CMAKE_SOURCE_DIR}/src/server/options/options.h)
SET(OPTIONS_SOURCES ${CMAKE_SOURCE_DIR}/src/server/options/options.cpp)

SET(SERVER_HTTP_HEADERS
  ${CMAKE_SOURCE_DIR}/src/server/http/handler.h
  ${CMAKE_SOURCE_DIR}/src/server/http/client.h
  ${CMAKE_SOURCE_DIR}/src/server/http/server.h
)

SET(SERVER_HTTP_SOURCES
  ${CMAKE_SOURCE_DIR}/src/server/http/handler.cpp
  ${CMAKE_SOURCE_DIR}/src/server/http/client.cpp
  ${CMAKE_SOURCE_DIR}/src/server/http/server.cpp
)

SET(SERVER_VODS_HEADERS
  ${CMAKE_SOURCE_DIR}/src/server/vods/handler.h
  ${CMAKE_SOURCE_DIR}/src/server/vods/client.h
  ${CMAKE_SOURCE_DIR}/src/server/vods/server.h
)

SET(SERVER_VODS_SOURCES
  ${CMAKE_SOURCE_DIR}/src/server/vods/handler.cpp
  ${CMAKE_SOURCE_DIR}/src/server/vods/client.cpp
  ${CMAKE_SOURCE_DIR}/src/server/vods/server.cpp
)

SET(SERVER_DAEMON_HEADERS
  ${CMAKE_SOURCE_DIR}/src/server/daemon/client.h
  ${CMAKE_SOURCE_DIR}/src/server/daemon/server.h
  ${CMAKE_SOURCE_DIR}/src/server/daemon/commands.h
  ${CMAKE_SOURCE_DIR}/src/server/daemon/commands_factory.h

  ${CMAKE_SOURCE_DIR}/src/server/daemon/commands_info/service/details/shots.h
  ${CMAKE_SOURCE_DIR}/src/server/daemon/commands_info/service/sync_info.h
  ${CMAKE_SOURCE_DIR}/src/server/daemon/commands_info/service/server_info.h
  ${CMAKE_SOURCE_DIR}/src/server/daemon/commands_info/service/prepare_info.h

  ${CMAKE_SOURCE_DIR}/src/server/daemon/commands_info/stream/stream_info.h
  ${CMAKE_SOURCE_DIR}/src/server/daemon/commands_info/stream/start_info.h
  ${CMAKE_SOURCE_DIR}/src/server/daemon/commands_info/stream/quit_status_info.h
  ${CMAKE_SOURCE_DIR}/src/server/daemon/commands_info/stream/restart_info.h
  ${CMAKE_SOURCE_DIR}/src/server/daemon/commands_info/stream/stop_info.h
  ${CMAKE_SOURCE_DIR}/src/server/daemon/commands_info/stream/get_log_info.h
)

SET(SERVER_DAEMON_SOURCES
  ${CMAKE_SOURCE_DIR}/src/server/daemon/client.cpp
  ${CMAKE_SOURCE_DIR}/src/server/daemon/server.cpp
  ${CMAKE_SOURCE_DIR}/src/server/daemon/commands.cpp
  ${CMAKE_SOURCE_DIR}/src/server/daemon/commands_factory.cpp

  ${CMAKE_SOURCE_DIR}/src/server/daemon/commands_info/service/details/shots.cpp
  ${CMAKE_SOURCE_DIR}/src/server/daemon/commands_info/service/sync_info.cpp
  ${CMAKE_SOURCE_DIR}/src/server/daemon/commands_info/service/server_info.cpp
  ${CMAKE_SOURCE_DIR}/src/server/daemon/commands_info/service/prepare_info.cpp

  ${CMAKE_SOURCE_DIR}/src/server/daemon/commands_info/stream/stream_info.cpp
  ${CMAKE_SOURCE_DIR}/src/server/daemon/commands_info/stream/start_info.cpp
  ${CMAKE_SOURCE_DIR}/src/server/daemon/commands_info/stream/quit_status_info.cpp
  ${CMAKE_SOURCE_DIR}/src/server/daemon/commands_info/stream/restart_info.cpp
  ${CMAKE_SOURCE_DIR}/src/server/daemon/commands_info/stream/stop_info.cpp
  ${CMAKE_SOURCE_DIR}/src/server/daemon/commands_info/stream/get_log_info.cpp
)

SET(SERVER_HEADERS
  ${CMAKE_SOURCE_DIR}/src/server/base/iserver_handler.h
  ${CMAKE_SOURCE_DIR}/src/server/base/ihttp_requests_observer.h

  ${CMAKE_SOURCE_DIR}/src/server/child.h
  ${CMAKE_SOURCE_DIR}/src/server/child_stream.h
  ${CMAKE_SOURCE_DIR}/src/server/links_holder_ts.h
  ${CMAKE_SOURCE_DIR}/src/server/process_slave_wrapper.h
  ${CMAKE_SOURCE_DIR}/src/server/config.h

  ${SERVER_HTTP_HEADERS}
  ${SERVER_VODS_HEADERS}
  ${SERVER_DAEMON_HEADERS}
  ${PIPE_HEADERS}
  ${TCP_HEADERS}
  ${UTILS_HEADERS}
  ${OPTIONS_HEADERS}
)
SET(SERVER_SOURCES
  ${CMAKE_SOURCE_DIR}/src/server/base/iserver_handler.cpp
  ${CMAKE_SOURCE_DIR}/src/server/base/ihttp_requests_observer.cpp

  ${CMAKE_SOURCE_DIR}/src/server/child.cpp
  ${CMAKE_SOURCE_DIR}/src/server/child_stream.cpp
  ${CMAKE_SOURCE_DIR}/src/server/links_holder_ts.cpp
  ${CMAKE_SOURCE_DIR}/src/server/process_slave_wrapper.cpp
  ${CMAKE_SOURCE_DIR}/src/server/config.cpp

  ${SERVER_HTTP_SOURCES}
  ${SERVER_VODS_SOURCES}
  ${SERVER_DAEMON_SOURCES}
  ${PIPE_SOURCES}
  ${TCP_SOURCES}
  ${UTILS_SOURCES}
  ${OPTIONS_SOURCES}
)

SET(PERF_OBSERVER_HEADERS
  ${CMAKE_SOURCE_DIR}/src/server/gpu_stats/perf_monitor.h
)
SET(PERF_OBSERVER_SOURCES
  ${CMAKE_SOURCE_DIR}/src/server/gpu_stats/perf_monitor.cpp
)

#gpu nvidia
FIND_PACKAGE(NVML)
IF(NVML_FOUND)
  SET(DAEMON_LIBRARIES ${DAEMON_LIBRARIES} ${NVML_LIBRARIES})
  SET(PERF_OBSERVER_HEADERS ${PERF_OBSERVER_HEADERS} ${CMAKE_SOURCE_DIR}/src/server/gpu_stats/nvidia_monitor.h)
  SET(PERF_OBSERVER_SOURCES ${PERF_OBSERVER_SOURCES} ${CMAKE_SOURCE_DIR}/src/server/gpu_stats/nvidia_monitor.cpp)
  SET(PRIVATE_INCLUDE_DIRECTORIES_SLAVE ${PRIVATE_INCLUDE_DIRECTORIES_SLAVE} ${NVML_INCLUDE_DIRS})
  SET(PRIVATE_COMPILE_DEFINITIONS_SLAVE ${PRIVATE_COMPILE_DEFINITIONS_SLAVE} -DHAVE_NVML)

  # ibnvidia-ml.so.1
  GET_FILENAME_COMPONENT(NVML_LIBRARY_WITHOUT_SYMLINK ${NVML_LIBRARIES} REALPATH)
  GET_FILENAME_COMPONENT(NVML_LIBRARY_NAME ${NVML_LIBRARY_WITHOUT_SYMLINK} NAME)
  STRING(REGEX REPLACE "[^so]+$" ".1" NVML_LNNAME ${NVML_LIBRARY_NAME})
  #libSDL2-2.0.so.0
  INSTALL(FILES ${NVML_LIBRARY_WITHOUT_SYMLINK} DESTINATION ${LIB_INSTALL_DESTINATION} RENAME ${NVML_LNNAME} COMPONENT RUNTIME)
ENDIF(NVML_FOUND)

#gpu intel
SET(CTT_METRICS_PATH "/usr/local/share/mfx/samples/")
FIND_LIBRARY(CTT_METRICS_LIBRARY
  NAMES cttmetrics
  PATHS ${CTT_METRICS_PATH}
)
MESSAGE("CTT_METRICS_LIBRARY: ${CTT_METRICS_LIBRARY}")
IF (CTT_METRICS_LIBRARY)
  SET(DAEMON_LIBRARIES ${DAEMON_LIBRARIES} ${CTT_METRICS_LIBRARY})
  SET(PERF_OBSERVER_HEADERS ${PERF_OBSERVER_HEADERS} ${CMAKE_SOURCE_DIR}/src/server/gpu_stats/intel_monitor.h)
  SET(PERF_OBSERVER_SOURCES ${PERF_OBSERVER_SOURCES} ${CMAKE_SOURCE_DIR}/src/server/gpu_stats/intel_monitor.cpp)
  SET(PRIVATE_COMPILE_DEFINITIONS_SLAVE ${PRIVATE_COMPILE_DEFINITIONS_SLAVE} -DHAVE_CTT_METRICS)
  INSTALL(FILES ${CTT_METRICS_LIBRARY} DESTINATION ${LIB_INSTALL_DESTINATION} COMPONENT RUNTIME)
ENDIF(CTT_METRICS_LIBRARY)

IF(OS_POSIX)
  SET(SERVER_SOURCES ${SERVER_SOURCES} ${CMAKE_SOURCE_DIR}/src/server/process_slave_wrapper_posix.cpp)
ELSEIF(OS_WIN)
  SET(SERVER_SOURCES ${SERVER_SOURCES} ${CMAKE_SOURCE_DIR}/src/server/process_slave_wrapper_win.cpp)
ENDIF(OS_POSIX)

SET(DAEMON_SOURCES
  ${SERVER_HEADERS} ${SERVER_SOURCES}
  ${PERF_OBSERVER_HEADERS} ${PERF_OBSERVER_SOURCES}
)
SET(DAEMON_LIBRARIES
  ${DAEMON_LIBRARIES}
  ${FASTOTV_CPP_LIBRARIES}
  ${COMMON_LIBRARIES}
  ${JSONC_LIBRARIES}
  ${PLATFORM_LIBRARIES}
  ${STREAMER_COMMON}
  ${OPENSSL_LIBRARIES}
)
SET(PRIVATE_INCLUDE_DIRECTORIES_SLAVE
  ${PRIVATE_INCLUDE_DIRECTORIES_SLAVE}
  ${FASTOTV_CPP_INCLUDE_DIRS}
  ${COMMON_INCLUDE_DIRS}
  ${CMAKE_SOURCE_DIR}/src
)
SET(CORE_LIBRARY ${LIB_INSTALL_DESTINATION}/${CMAKE_SHARED_LIBRARY_PREFIX}${STREAMER_CORE}${CMAKE_SHARED_LIBRARY_SUFFIX})

SET(RUN_DIR_PATH "/var/run/${STREAMER_SERVICE_NAME}")
SET(PIDFILE_PATH "${RUN_DIR_PATH}/${STREAMER_SERVICE_NAME}.pid")
SET(USER_NAME ${PROJECT_NAME_LOWERCASE})
SET(USER_GROUP ${PROJECT_NAME_LOWERCASE})
SET(CONFIG_PATH "/etc/${STREAMER_SERVICE_NAME}.conf")

SET(STREAM_DEFINITIONS
  -DRELATIVE_SOURCE_DIR="${RELATIVE_SOURCE_DIR}"
  -DCORE_LIBRARY="${CORE_LIBRARY}"
  -DSTREAMER_NAME="${STREAMER_NAME}"
)

SET(PRIVATE_COMPILE_DEFINITIONS_SLAVE
  ${PRIVATE_COMPILE_DEFINITIONS_SLAVE}
  ${STREAM_DEFINITIONS}
  -DCONFIG_PATH="${CONFIG_PATH}"
  -DPIDFILE_PATH="${PIDFILE_PATH}"
  -DSTREAMER_SERVICE_NAME="${STREAMER_SERVICE_NAME}"
  -DCLIENT_PORT=${STREAMER_SERVICE_PORT}
  -DHTTP_PORT=${STREAMER_SERVICE_HTTP_PORT}
  -DVODS_PORT=${STREAMER_SERVICE_VODS_PORT}
  -DCODS_PORT=${STREAMER_SERVICE_CODS_PORT}
  -DCODS_TTL=${STREAMER_SERVICE_CODS_TTL}
  -DFILES_TTL=${STREAMER_SERVICE_FILES_TTL}
  -DSTREAMER_SERVICE_STREAMLINK_PATH="${STREAMER_SERVICE_STREAMLINK_PATH}"
)

IF(OS_WIN)
  SET(PRIVATE_COMPILE_DEFINITIONS_SLAVE ${PRIVATE_COMPILE_DEFINITIONS_SLAVE} -DSTREAMER_EXE_NAME="${STREAMER_EXE_NAME}")
ENDIF(OS_WIN)

SET(EXE_DAEMON_SOURCES ${CMAKE_SOURCE_DIR}/src/server/daemon_slave.cpp)

ADD_EXECUTABLE(${STREAMER_SERVICE_NAME_EXE} ${DAEMON_SOURCES} ${EXE_DAEMON_SOURCES})
TARGET_INCLUDE_DIRECTORIES(${STREAMER_SERVICE_NAME_EXE} PRIVATE ${PRIVATE_INCLUDE_DIRECTORIES_SLAVE})
TARGET_COMPILE_DEFINITIONS(${STREAMER_SERVICE_NAME_EXE} PRIVATE ${PRIVATE_COMPILE_DEFINITIONS_SLAVE})
TARGET_LINK_LIBRARIES(${STREAMER_SERVICE_NAME_EXE} ${DAEMON_LIBRARIES})

IF(PROJECT_BUILD_TYPE_VERSION STREQUAL "release")
  STRIP_TARGET(${STREAMER_SERVICE_NAME_EXE})
ENDIF(PROJECT_BUILD_TYPE_VERSION STREQUAL "release")
INSTALL(TARGETS ${STREAMER_SERVICE_NAME_EXE} DESTINATION ${TARGET_INSTALL_DESTINATION} COMPONENT APPLICATIONS)

IF(OS_WIN)
  ADD_EXECUTABLE(${STREAMER_EXE_NAME} ${CMAKE_SOURCE_DIR}/src/server/stream_win.cpp ${TCP_SOURCES})
  TARGET_INCLUDE_DIRECTORIES(${STREAMER_EXE_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/src)
  TARGET_COMPILE_DEFINITIONS(${STREAMER_EXE_NAME} PRIVATE ${STREAM_DEFINITIONS})
  TARGET_LINK_LIBRARIES(${STREAMER_EXE_NAME} ${COMMON_LIBRARIES} ${PLATFORM_LIBRARIES} ${STREAMER_COMMON} ${FASTOTV_CPP_LIBRARIES})

  IF(PROJECT_BUILD_TYPE_VERSION STREQUAL "release")
    STRIP_TARGET(${STREAMER_EXE_NAME})
  ENDIF(PROJECT_BUILD_TYPE_VERSION STREQUAL "release")
  INSTALL(TARGETS ${STREAMER_EXE_NAME} DESTINATION ${TARGET_INSTALL_DESTINATION} COMPONENT APPLICATIONS)
ENDIF(OS_WIN)

SET(EXECUTABLE_FOLDER_PATH ${CMAKE_INSTALL_PREFIX}/bin)

IF(OS_WINDOWS)
ELSEIF(OS_MACOSX)
ELSEIF(OS_LINUX OR OS_FREEBSD)
  SET(EXECUTABLE_PATH ${EXECUTABLE_FOLDER_PATH}/${STREAMER_SERVICE_NAME} CACHE INTERNAL "Daemon path: ${EXECUTABLE_PATH}")
ENDIF(OS_WINDOWS)

# script
SET(SERVICE_START_SCRIPT_GEN_PATH ${CMAKE_BINARY_DIR}/service/${STREAMER_SERVICE_NAME})
GEN_START_SCRIPT(${SERVICE_START_SCRIPT_GEN_PATH} ${STREAMER_SERVICE_NAME_EXE})
INSTALL(PROGRAMS ${SERVICE_START_SCRIPT_GEN_PATH} DESTINATION
  ${TARGET_INSTALL_DESTINATION} COMPONENT APPLICATIONS
)

# service
IF(OS_LINUX OR OS_FREEBSD)
  SET(SERVICE_SCRIPT_GEN_PATH ${CMAKE_BINARY_DIR}/service/${STREAMER_SERVICE_NAME}.service)
  GEN_SERVICE_SERVICE_FILE(${SERVICE_SCRIPT_GEN_PATH}
    ${STREAMER_SERVICE_NAME} ${STREAMER_SERVICE_NAME_EXE}
    ${EXECUTABLE_PATH}
    ${RUN_DIR_PATH}
    ${PIDFILE_PATH}
    ${USER_NAME} ${USER_GROUP}
    ${PROJECT_SUMMARY}
  )
  INSTALL(FILES ${SERVICE_SCRIPT_GEN_PATH} DESTINATION /etc/systemd/system/)

  SET(SERVICE_DEB_SCRIPT_GEN_PATH ${CMAKE_BINARY_DIR}/service/${STREAMER_SERVICE_NAME}.debian)
  GEN_DEBIAN_SERVICE_FILE(${SERVICE_DEB_SCRIPT_GEN_PATH}
    ${STREAMER_SERVICE_NAME} ${STREAMER_SERVICE_NAME_EXE}
    ${EXECUTABLE_PATH}
    ${RUN_DIR_PATH}
    ${PIDFILE_PATH}
    ${USER_NAME} ${USER_GROUP}
    ${PROJECT_SUMMARY}
  )
  INSTALL(FILES ${SERVICE_DEB_SCRIPT_GEN_PATH}
    DESTINATION /etc/init.d
    RENAME ${STREAMER_SERVICE_NAME}
    PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
ENDIF(OS_LINUX OR OS_FREEBSD)

# config file
SET(SERVICE_CONF_GEN_PATH ${CMAKE_BINARY_DIR}/service/${STREAMER_SERVICE_NAME}.conf)
CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/install/${PROJECT_NAME_LOWERCASE}/service/service.conf.in
  ${SERVICE_CONF_GEN_PATH} @ONLY IMMEDIATE
)
IF(NOT EXISTS ${CONFIG_PATH} OR CPACK_SUPPORT)
  INSTALL(FILES ${SERVICE_CONF_GEN_PATH} DESTINATION /etc/)
ENDIF(NOT EXISTS ${CONFIG_PATH} OR CPACK_SUPPORT)

IF (DEVELOPER_CHECK_STYLE)
  SET(CHECK_SOURCES_DAEMON ${DAEMON_SOURCES} ${EXE_DAEMON_SOURCES})
  REGISTER_CHECK_STYLE_TARGET(check_style_${STREAMER_SERVICE_NAME} "${CHECK_SOURCES_DAEMON}")
  REGISTER_CHECK_INCLUDES_TARGET(${STREAMER_SERVICE_NAME_EXE})
ENDIF(DEVELOPER_CHECK_STYLE)

IF(DEVELOPER_ENABLE_TESTS)
  FIND_PACKAGE(GTest REQUIRED)

  ## Unit tests
  SET(PRIVATE_INCLUDE_DIRECTORIES_UNIT_TESTS
    ${PRIVATE_INCLUDE_DIRECTORIES_UNIT_TESTS}
    ${CMAKE_SOURCE_DIR}/src
  )
  SET(UNIT_TESTS_LIBS
      ${GTEST_BOTH_LIBRARIES}
      ${STREAMER_COMMON}
      ${PLATFORM_LIBRARIES})
  SET(UNIT_TESTS unit_tests_server)
  ADD_EXECUTABLE(${UNIT_TESTS}
    ${CMAKE_SOURCE_DIR}/tests/server/unit_test_server.cpp ${OPTIONS_SOURCES}
  )
  TARGET_INCLUDE_DIRECTORIES(${UNIT_TESTS} PRIVATE ${PRIVATE_INCLUDE_DIRECTORIES_UNIT_TESTS} ${JSONC_INCLUDE_DIRS})
  TARGET_LINK_LIBRARIES(${UNIT_TESTS} ${UNIT_TESTS_LIBS} ${DAEMON_LIBRARIES})
  ADD_TEST_TARGET(${UNIT_TESTS})
  SET_PROPERTY(TARGET ${UNIT_TESTS} PROPERTY FOLDER "Unit tests")
ENDIF(DEVELOPER_ENABLE_TESTS)
